﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;

namespace LimpaGaragem.DAO.Product
{
    public class Status
    {
        /// <summary>
        /// Return list of status
        /// </summary>
        /// <returns></returns>
        public List<LimpaGaragem.Model.Product.Status> GetListOfStatus()
        {
            try
            {
                Framework.DataAccess objDataAccess = new Framework.DataAccess();
                DataTable objDataTable = objDataAccess.ReturnDataTable(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString, Framework.DataAccess.QueryType.Procedure, "PR009_ListProductStatus", 0);

                List<LimpaGaragem.Model.Product.Status> objListOfStatus = new List<LimpaGaragem.Model.Product.Status>();
                foreach (DataRow objDataRow in objDataTable.Rows)
                {
                    LimpaGaragem.Model.Product.Status objStatus = new LimpaGaragem.Model.Product.Status();
                    objStatus.ID = Convert.ToInt32(objDataRow["ID_STATUS"]);
                    objStatus.Name = objDataRow["NM_STATUS"].ToString();
                    objStatus.Description = objDataRow["DS_STATUS"].ToString();
                    objListOfStatus.Add(objStatus);
                }
                return objListOfStatus;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// Return data of status
        /// </summary>
        /// <returns></returns>
        public LimpaGaragem.Model.Product.Status GetStatus(int IDStatus)
        {
            try
            {
                Framework.DataAccess objDataAccess = new Framework.DataAccess();

                //PARAMETERS
                List<SqlParameter> objListOfParameters = new List<SqlParameter>();
                objListOfParameters.Add(new SqlParameter("@ID_STATUS", IDStatus));

                //RETURN DATA
                DataTable objDataTable = objDataAccess.ReturnDataTable(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString, Framework.DataAccess.QueryType.Procedure, "PR009_SelectProductStatus", 0, objListOfParameters);

                LimpaGaragem.Model.Product.Status objStatus = null;
                if (objDataTable.Rows.Count > 0)
                {
                    objStatus = new LimpaGaragem.Model.Product.Status();
                    objStatus.ID = IDStatus;
                    objStatus.Name = objDataTable.Rows[0]["NM_RATE_SCORE"].ToString();
                    objStatus.Description = objDataTable.Rows[0]["NM_RATE_SCORE"].ToString();
                }
                return objStatus;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
